<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>






<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,Dalvik,AOSP," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="《深入理解Android虚拟机》 本书的阅读笔记，整体来说这本书只适合通读，入门了解。通过对比阅读，发现很多内容不够严谨，同时内容安排上有拼凑之嫌。如果你和我一样，因为名字想阅读这本书，建议在这本书上花费的时间不要超过一天。">
<meta name="keywords" content="Android,Dalvik,AOSP">
<meta property="og:type" content="article">
<meta property="og:title" content="深入理解Android虚拟机读书笔记">
<meta property="og:url" content="http://imesong.com/2016/07/15/2016/深入理解Android虚拟机读书笔记/index.html">
<meta property="og:site_name" content="imesong">
<meta property="og:description" content="《深入理解Android虚拟机》 本书的阅读笔记，整体来说这本书只适合通读，入门了解。通过对比阅读，发现很多内容不够严谨，同时内容安排上有拼凑之嫌。如果你和我一样，因为名字想阅读这本书，建议在这本书上花费的时间不要超过一天。">
<meta property="og:image" content="http://7xrkqt.com1.z0.glb.clouddn.com/blogimage/2016/31JVM%E6%9E%84%E6%88%90%E5%9B%BE.png">
<meta property="og:image" content="http://7xrkqt.com1.z0.glb.clouddn.com/blogimage/2016/32JVM%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%BB%93%E6%9E%84%E6%A1%86%E5%9B%BE.png">
<meta property="og:updated_time" content="2017-04-19T04:36:26.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="深入理解Android虚拟机读书笔记">
<meta name="twitter:description" content="《深入理解Android虚拟机》 本书的阅读笔记，整体来说这本书只适合通读，入门了解。通过对比阅读，发现很多内容不够严谨，同时内容安排上有拼凑之嫌。如果你和我一样，因为名字想阅读这本书，建议在这本书上花费的时间不要超过一天。">
<meta name="twitter:image" content="http://7xrkqt.com1.z0.glb.clouddn.com/blogimage/2016/31JVM%E6%9E%84%E6%88%90%E5%9B%BE.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://imesong.com/2016/07/15/2016/深入理解Android虚拟机读书笔记/"/>





  <title> 深入理解Android虚拟机读书笔记 | imesong </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb36183ed65a7652b909d352ab2166";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">imesong</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">我们的征途是星辰大海</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://imesong.com/2016/07/15/2016/深入理解Android虚拟机读书笔记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="imesong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://s.gravatar.com/avatar/bd2525e0ecc6d8022339c7dce27065c0?s=160">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="imesong">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                深入理解Android虚拟机读书笔记
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-07-15T21:01:26+08:00">
                2016-07-15
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index">
                    <span itemprop="name">Android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <p><a href="https://book.douban.com/subject/26013542/" target="_blank" rel="external">《深入理解Android虚拟机》</a> 本书的阅读笔记，整体来说这本书只适合通读，入门了解。通过对比阅读，发现很多内容不够严谨，同时内容安排上有拼凑之嫌。如果你和我一样，因为名字想阅读这本书，建议在这本书上花费的时间不要超过一天。</p>
<a id="more"></a>
<h1 id="主要内容"><a href="#主要内容" class="headerlink" title="主要内容"></a>主要内容</h1><p>本书内容共13章，其中第1章[Android系统介绍]，第2章[Android系统结构]直接跳过，第7章[生命周期管理]明显拼凑，和Dalvik虚拟机关系不大，并且这章内容属于初级Android开发掌握的，第11章[JNI接口]介绍了基础的JNI编程，了解NDK的可以跳过。删减之后，剩下的内容就是这些</p>
<ul>
<li>虚拟机概述</li>
<li>编译和调试Dalvik</li>
<li>Dalvik 虚拟机运作流程</li>
<li>Dex优化和安全管理</li>
<li>内存分配策略</li>
<li>垃圾收集</li>
<li>线程管理</li>
<li>异常管理</li>
</ul>
<h1 id="虚拟机概述"><a href="#虚拟机概述" class="headerlink" title="虚拟机概述"></a>虚拟机概述</h1><p>在没有接触和了解虚拟机之前，总觉得虚拟机是很高深，很‘底层’，很容易望文生义。虚拟机其实就是一套解释规范的执行者，解析规范的格式的文件，执行文件中的内容。这章概述主要介绍JVM虚拟机和Dalvik虚拟机的结构，原理。JVM部分建议参考<a href="https://book.douban.com/subject/25792515/" target="_blank" rel="external">JAVA虚拟机规范SE7</a>。通过阅读本章和规范，了解虚拟机结构和关键术语。</p>
<h3 id="JVM虚拟机"><a href="#JVM虚拟机" class="headerlink" title="JVM虚拟机"></a>JVM虚拟机</h3><p><img src="http://7xrkqt.com1.z0.glb.clouddn.com/blogimage/2016/31JVM%E6%9E%84%E6%88%90%E5%9B%BE.png" alt="JVM构成图"></p>
<p><strong>Java虚拟机的数据类型</strong></p>
<ul>
<li>byte</li>
<li>short</li>
<li>int </li>
<li>long</li>
<li>float</li>
<li>double</li>
<li>char</li>
<li>object 对一个Java object 的4个字节引用</li>
<li>returnAddress 4字节，用于 jsr/ret/jsr-w/ret-w指令</li>
</ul>
<p><strong>Java虚拟机的体系结构</strong></p>
<ul>
<li>指令集</li>
<li>寄存器</li>
<li>栈</li>
<li>无用单元收集堆(Garbage-collected-heap)</li>
<li>方法区域</li>
</ul>
<p><img src="http://7xrkqt.com1.z0.glb.clouddn.com/blogimage/2016/32JVM%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%BB%93%E6%9E%84%E6%A1%86%E5%9B%BE.png" alt="Java虚拟机的结构框图"></p>
<p>Java虚拟机基于栈的，这点是和Dalvik虚拟机主要区别之一。</p>
<h3 id="Dalvik虚拟机"><a href="#Dalvik虚拟机" class="headerlink" title="Dalvik虚拟机"></a>Dalvik虚拟机</h3><p>dx 工具用来讲 .class 文件转换为 dex 文件。转换过程中，会进行优化，重复的字符串和其它常数在dex中只会保留一份。一个未压缩的dex通常比已经压缩的jar小一点。</p>
<p>Dalvik 和 Java虚拟机的差异：</p>
<blockquote>
<ul>
<li>Dalvik 早期没有JIT，2.2版本开始支持JIT技术</li>
<li>Dalvik 使用自己的bytecode ,并非适用java的bytecode</li>
<li>Dalvik 基于寄存器(Register),JVM 基于栈(Stack)</li>
<li>Dalvik 通过Zygote 进行 Class Preloading ,Zygote 会完成虚拟机的初始化，这也是雨JVM虚拟机不同之处。</li>
</ul>
</blockquote>
<h3 id="Dalvik虚拟机的初始化"><a href="#Dalvik虚拟机的初始化" class="headerlink" title="Dalvik虚拟机的初始化"></a>Dalvik虚拟机的初始化</h3><ul>
<li>初始化准备工作</li>
<li>初始化跟踪显示系统</li>
<li>初始化垃圾回收器</li>
<li>初始化线程列表和主线程环境参数</li>
<li>分配内部操作方法的表格内存</li>
<li>初始化虚拟机的指令码相关内容</li>
<li>分配指令寄存器状态的内存</li>
<li>初始化虚拟机基本的Java库</li>
<li>初始化虚拟机使用的异常Java类库</li>
<li>释放字符串哈希表</li>
<li>初始化本地方法库的表</li>
<li>初始化内部本地方法</li>
<li>初始化JNI调用表</li>
<li>缓存Java类里的反射类</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag"># Android</a>
          
            <a href="/tags/Dalvik/" rel="tag"># Dalvik</a>
          
            <a href="/tags/AOSP/" rel="tag"># AOSP</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/08/12/2016/LinuxShell脚本攻略/" rel="next" title="LinuxShell脚本攻略">
                <i class="fa fa-chevron-left"></i> LinuxShell脚本攻略
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/04/19/2016LearningList/" rel="prev" title="2016LearningList">
                2016LearningList <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="https://s.gravatar.com/avatar/bd2525e0ecc6d8022339c7dce27065c0?s=160"
               alt="imesong" />
          <p class="site-author-name" itemprop="name">imesong</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/imesong" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#主要内容"><span class="nav-number">1.</span> <span class="nav-text">主要内容</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#虚拟机概述"><span class="nav-number">2.</span> <span class="nav-text">虚拟机概述</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#JVM虚拟机"><span class="nav-number">2.0.1.</span> <span class="nav-text">JVM虚拟机</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Dalvik虚拟机"><span class="nav-number">2.0.2.</span> <span class="nav-text">Dalvik虚拟机</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Dalvik虚拟机的初始化"><span class="nav-number">2.0.3.</span> <span class="nav-text">Dalvik虚拟机的初始化</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">imesong</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  





  





  






  





  

  

  

  

  

</body>
</html>
